#include "dialog.h"
#include "ui_dialog.h"

Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);

    this->setWindowFlags(Qt::FramelessWindowHint);

    this->initSet();

    connect(&timer0,SIGNAL(timeout()),this,SLOT(getTime()));
    timer0.start(500);

}

Dialog::~Dialog()
{
    delete ui;
}

void Dialog::initSet()
{
    QIcon icon(tr(":/images/logo.ico"));
    this->setWindowIcon(icon);

    QPixmap pixmap(tr(":/images/battery524.ico"));
    ui->batteryLabel->setPixmap(pixmap);

    pixmap.load(tr(":/images/sd24.ico"));
    ui->sdLabel->setPixmap(pixmap);

    this->getTime();

    //pixmap.load(tr(":/images/monitor.ico"));
    //ui->monitorBtn->setP
}

//关机
void Dialog::on_shutdownBtn_clicked()
{
    QMessageBox box;
    QIcon icon(tr(":/images/logo.ico"));
    box.setWindowIcon(icon);
    int ret = box.warning(this, tr("关机"),
                      tr("是否关机？"),
                      QMessageBox::Yes | QMessageBox::No);
    if(ret == QMessageBox::Yes)
    {
        timer0.stop();
        this->close();
    }
}

//获取系统时间
void Dialog::getTime()
{
    QDateTime time = QDateTime::currentDateTime();//获取系统现在的时间

    QString str = time.toString("yyyy-MM-dd hh:mm:ss"); //设置显示格式

    ui->timeLabel->setText(str);//在标签上显示时间
}

//显示实时监测
void Dialog::on_monitorBtn_clicked()
{
   //qDebug()<<"show";

   Monitor *monitor;
   monitor = new Monitor;
   monitor->show();
   //monitor.show();
}
